package framework;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.ws.rs.core.Cookie;

public class Utility {
	public static synchronized byte[] inputStreamToByteArray(InputStream inStream) throws IOException {
	    ByteArrayOutputStream baos = new ByteArrayOutputStream();
	    byte[] buffer = new byte[8192];
	    int bytesRead;
	    while ((bytesRead = inStream.read(buffer)) > 0) {
	        baos.write(buffer, 0, bytesRead);
	    }
	    return baos.toByteArray();
	}

	public static Cookie convertCookie(org.apache.http.cookie.Cookie cookie) {
		return new javax.ws.rs.core.Cookie(cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain(), cookie.getVersion());
	}

	public static Double[] lesser(Double[] data, int length) {
		double step = data.length / length;
		Double[] ret = new Double[length];
		for (int i = 0; i < length; i++) {
			ret[i] = data[(int)(i * step)];
		}
		return ret;
	}

}
